/*
    在Home页面中使用Redux中的store
    1.使用react-redux提供的高阶组件connect()
    2.使用react-redux提供的高阶组件 hooks api
*/
import * as React from 'react'
import {useSelector,useDispatch} from 'react-redux'
import { addCount,subCount,getList } from '../../store/actions/study'
import { useEffect } from 'react'
export default props=>{
    const count=useSelector(store=>store.study.count)
    const list=useSelector(store=>store.study.list)
    const dispatch=useDispatch()//是视图和store打交道的唯一方式
    useEffect(()=>{
        let data={
            page:1,
            tab:'',
            limit:5
        }
        // dispatch(getList(data))
        return()=>{}
    },[])
    return(
        <div>
            <h1>我是首页</h1>
            <h1>{count}</h1>
            <div>
                {
                    list.map(ele=>(
                        <div key={ele.id}>{ele.title}</div>
                    ))
                }
            </div>
            <button onClick={() => dispatch(addCount(2))}>+</button>
            <button onClick={() => dispatch(subCount(3))}>-</button>
        </div>
    )
}